package operations;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import com.vaadin.terminal.StreamResource;
import com.vaadin.terminal.StreamResource.StreamSource;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

public class Makaleopenoperation {
	
	public void makaleac(Window mainwindow,final String makaleurl,String filename)
	{
		Window window = new Window();
		((VerticalLayout) window.getContent()).setSizeFull();
//		window.setResizable(true);
//		window.setCaption("Exemplo PDF");
//		window.setWidth("800");
//		window.setHeight("600");
//		window.center();
		
		StreamSource s = new StreamResource.StreamSource() {

			public InputStream getStream() {
				try {
					File f = new File(makaleurl);
					FileInputStream fis = new FileInputStream(f);
					return fis;
					} catch (Exception e) {
					e.printStackTrace();
					return null;
					}
					
			}

		};
	
		StreamResource r = new StreamResource(s, filename, mainwindow.getApplication());
		Embedded e = new Embedded();
		e.setSizeFull();
		e.setType(Embedded.TYPE_BROWSER);
		r.setMIMEType("application/pdf");

		e.setSource(r);
//		layout.addComponent(e);
//		window.addComponent(e);
//		getWindow().addWindow(window);
		mainwindow.addComponent(e);
	}
	
	

}
